<template>
  <el-card class="home-card" shadow="always">
    <h2>欢迎回来，{{ username }}！</h2>
    <p>这是你的主页。</p>
    <el-button type="danger" @click="logout">退出登录</el-button>
  </el-card>
</template>

<script>
export default {
  name: 'UserHome',
  data() {
    return {
      username: ''
    };
  },
  created() {
    // 从 localStorage/sessionStorage 获取登录信息
    const user = JSON.parse(localStorage.getItem('currentUser'));
    if (user && user.username) {
      this.username = user.username;
    } else {
      // 未登录，跳转到登录页
      this.$router.push('/login');
    }
  },
  methods: {
    logout() {
      localStorage.removeItem('currentUser'); // 清除登录状态
      this.$router.push('/login');
    }
  }
};
</script>

<style scoped>
.home-card {
  max-width: 600px;
  margin: 100px auto;
  padding: 30px;
  text-align: center;
}
</style>